clc
clear

%% Set parameters
high=4.05;	% height
width=3.3;	% width
Length=20;	% Total length
distance=width;	% Wheel spacing

%% Calculate area
%%Functions referencing area

%% Calculate resistance
%Core idea: Change the length of h1 and the curvature of the surface c
%Given four types of nasal bridge heights h1, c varies at (0, Length] under different nasal bridge heights.
h1=1.2;%h1=0.2,0.4,0.6,0.8,1.0,1.2;
h2=0.5;
%Set environmental parameters (generally)
afa = 1/3*pi;  %wind direction
p = 1.29;  %air density
c = 0.48;  
i=0;
Q=zeros(20,180);% Set an empty matrix of 20 * 180 to store the results

for c=1:1:Length
    i=i+1;   %Count, a total of 20 radians
    S_sum(i)=area(h1,c);%The total area of the front of the vehicle
    n=0;
    for t=1:10:1800   
        n=n+1;    %Record the resistance value every 10 seconds to determine the final minimum resistance
       
    %Given the operating status of high-speed trains
        v_wind=0.00203*t;  %Given wind speed
        if t>=0 && t<=300    % The speed of high-speed rail during different acceleration periods
            v_rail = 0.278*t;    %The maximum is 83.4
        elseif t>300 && t<=1500
            v_rail = 83.4;
        else
            v_rail = -0.278*t+500.4;
        end
        
        v1=v_rail; v2=v_wind;S=0.5*S_sum(i);
        F_2= resistance( v1, v2, S);  %Using encapsulation, give v1 vehicle speed, v2 wind speed, and S area
        Q(i,n) = F_2;
    end
end


